<?php
class PriceList extends Zend_Db_Table_Abstract
{
	protected $_name = 'pricelist';

	public function getOtherOfferingsForLocaleId( $locale_id )
	{
		$select = $this->getAdapter()
		->select()
		->from('pricelist', array('package_type'=>'MasterDescription', 'package_id'=>'PriceListID', 'package_status'=>'Active'))
		->where("PriceListID IN (SELECT PkgPriceListId FROM packagepricelist)")
		->where('LocaleID  = ?', $locale_id);

		$stmt = $this->getAdapter()->query($select);
		$result = $stmt->fetchAll();

		if($result) {
			return $result;
		}
		else {
			return array();
		}
	}

	function SelectServicesByFuneralHomeLocaleId( $locale_id ) {
		
		$select = $this->getAdapter()->select()
		->from('pricelist', array(
		'item_category'=>'ItemCategory',
		'price_list_id'=>'PriceListId',
		'line_number'=>'ContractLineNumber',
		'item_description'=>'ContractDescription',
		'item_seq_number'=>'InvoiceSeqNo',
		'item_amount'=>'Price'
		)
		)
		->where('LocaleID  = ?', $locale_id);

		$result = $this->getAdapter()->fetchAll($select);
		$rows = array();
		if($result) {
			foreach ($result as $row) {

				$rows[$row['price_list_id']] = $row;
			}
			return $rows;
		}
		return $rows;
	}

	function SelectPackageByPackageId($fhPackageId) {
		
		$select = $this->getAdapter()->select()
		->from('pricelist', array(
		'item_category'=>'ItemCategory',
		'price_list_id'=>'PriceListId',
		'item_amount'=>'Price'
		)
		)
		->where("pricelistid IN (SELECT pricelistid FROM packagepricelist WHERE PkgPriceListId='$fhPackageId')");

		$rows = $this->getAdapter()->fetchAll($select);
		if($rows) {
			return $rows;
		}
		return array();
	}

	function getPackageDetailsForPackageId( $fhPackageId, $fhLocaleId ) {

		$priceList = $this->SelectServicesByFuneralHomeLocaleId($fhLocaleId);
		//print_r($priceList);exit;
		$results = array();

		//$rawxml = $soapClient->SelectPackageByPackageId( $fhPackageId, FDMS_PASSWORD );
		$rows = $this->SelectPackageByPackageId( $fhPackageId );

		$rows = array();
		foreach( $rows as $row1 )
		{

			$row = array();

			$price_list_id = $row1["PriceListID"];
			$item_description = $row1["ItemDescription"];
			$item_amount = $row1["ItemAmount"];

			$priceListRow = $priceList[$price_list_id];
			if(isset($priceListRow))
			{
				$row['item_category'] = $priceListRow['item_category'];
				$row['line_number'] = $priceListRow['line_number'];
				$row['item_seq_number'] = $priceListRow['item_seq_number'];
			}
			else
			{
				$row['item_category'] = '';
				$row['line_number'] = '';
				$row['item_seq_number'] = '';
			}

			$row['price_list_id'] = $price_list_id;
			$row['item_description'] = $item_description;
			$row['item_amount'] = $item_amount;

			$rows[] = $row;
		}

		$results['rows'] = $rows;

		return $results;
	}
}
?>